﻿#region Software License
/**************************************************************/
/*          Business of Software Consulting                   */
/*          FREE SOFTWARE LICENSE                             */
/**************************************************************/
/*  Directory Manifest Generator                              */
/*  by: Mike Cating                                           */
/*  © 2009 Business of Software Consulting                    */
/*                                                            */
/* BUSINESS OF SOFTWARE CONSULTING DISCLAIMS ALL WARRANTIES,  */
/* RESPONSIBILITIES, AND LIABILITIES ASSOCIATED WITH          */
/* USE OF THIS CODE IN ANY WAY, SHAPE, OR FORM                */
/* REGARDLESS HOW IMPLICIT, EXPLICIT, OR OBSCURE IT           */
/* IS. IF THERE IS ANYTHING QUESTIONABLE WITH REGARDS         */
/* TO THIS SOFTWARE BREAKING AND YOU GAIN A LOSS OF           */
/* ANY NATURE, WE ARE NOT THE RESPONSIBLE PARTY. USE          */
/* OF THIS SOFTWARE CREATES ACCEPTANCE OF THESE TERMS         */
/*                                                            */
/* USE OF THIS CODE MUST RETAIN ALL COPYRIGHT NOTICES         */
/* AND LICENSES (MEANING THIS TEXT).                          */
/*                                                            */
/**************************************************************/
#endregion


using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using BOSTools.DirectoryManifestGenerator;
using System.Diagnostics.CodeAnalysis;

namespace GenerateManifest
{
    class Program
    {
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                PrintInstructions();
                Environment.Exit(1);
            }

            string directory = "<empty>";
            string output = "<empty>";
            try
            {
                directory = args[0];
                output = args[1];

                DirectoryManifestController controller = new DirectoryManifestController(directory, output);
                controller.Process();
            }
            catch (Exception ex)
            {
                PrintException(ex, directory, output);
                Environment.Exit(2);
            }
        }

        private static void PrintInstructions()
        {
            Console.WriteLine("GenerateManifest.exe");
            Console.WriteLine("Open-source build tool by Mike Cating");
            Console.WriteLine();
            Console.WriteLine("Usage:");
            Console.WriteLine("GenerateManifest.exe <target directory> <output XML file path>");
            Console.WriteLine("\t<target directory>: The directory against which to generate the manifest");
            Console.WriteLine("\t<output XML file path>: The file path and name to use for the output manifest");
        }

        private static void PrintException(Exception ex, string directory, string output)
        {
            Console.WriteLine("There was an error processing directory {0} to manifest file {1}.", directory, output);
            Console.WriteLine("Message: {0}", ex.Message);
            Console.WriteLine("Source: {0}", ex.Source);
            Console.WriteLine("Call Stack: {0}", ex.StackTrace);
        }
    }
}
